//
//  NewsViewController.m
//  FootballSport
//
//  Created by lanou3g on 15/5/28.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "NewsViewController.h"
#import "MatchAddChildVC.h"
@interface NewsViewController ()<UIScrollViewDelegate>

@end

@implementation NewsViewController


-(instancetype)init{
   
    if (self = [super init]) {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(execute:) name:segmentSendNotification object:nil];
    }
    return self;
}



- (void)setupSubView{
    
    
        _newsScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds),CGRectGetHeight(self.view.bounds)-64-44)];
      
    
        _newsScrollV.contentSize = CGSizeMake(4*CGRectGetWidth(self.view.bounds), 0);
    
        _newsScrollV.bounces =NO;
        _newsScrollV.delegate = self;
        _newsScrollV.pagingEnabled = YES;
        [self.view addSubview:self.newsScrollV];
    
        [MatchAddChildVC  getChildWithNewsVC:self];
        _newsScrollV.bounces =NO;
    
   
  
}






- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self setupSubView];
    
    // Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
}


- (void)execute:(NSNotification*) notification{
    NSNumber *number = notification.object;
    self.newsScrollV.contentOffset =CGPointMake(CGRectGetWidth(self.view.bounds)*[number integerValue], 0);
    
}

#pragma ---scrollViewDelegate方法实现---
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSNumber *number = [NSNumber numberWithInteger:(NSInteger)(self.newsScrollV.contentOffset.x/CGRectGetWidth(self.view.bounds)+0.3)];
    
    //发送消息
    [[NSNotificationCenter defaultCenter] postNotificationName:scrollSendNotification object:number];
    [[NSNotificationCenter defaultCenter] postNotificationName:segmentSendNotification object:number];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
